package com.ipacs.abs4j.testcode.absSchema;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class FlowDefinitionParser extends AbstractAbsBeanDefinitionParser {
	
	
	protected Class<DefaultMessageProcessChain> getBeanClass(Element element){
		return DefaultMessageProcessChain.class	;
		
	}
	
	protected void doParse(Element element,ParserContext ctx,BeanDefinitionBuilder builder) {
		
		ManagedList<BeanDefinition> Processors= new ManagedList<BeanDefinition>() ;
		NodeList nl = element.getChildNodes() ;
		
		for(int i =0 ;i<nl.getLength();++i) {
			
			Node node = (Node) nl.item(i) ;
			String nodename = node.getNodeName() ;
			
			System.out.println("Flow parser: node" +i+" "+ nodename);
			if(node.getNodeType()==1) {
				System.out.println("Flow parser do") ;
				Element elem = (Element) node ;	 
			   if(nodename.endsWith("packets")){	
			    
			   }else {
				   
				BeanDefinitionParserDelegate pd = new BeanDefinitionParserDelegate(ctx.getReaderContext()) ;
				BeanDefinition bd= pd.parseCustomElement(elem, builder.getBeanDefinition()) ;
				Processors.add(bd) ; 
				
			   }
			}
		}
		
		builder.addPropertyValue("processors", Processors) ;
		
		
	}

}
